/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

class kSprite;
class kEngine;
class kMaterial;

#include "kmesh2d.h"
#include "kimage.h"
#include "kblend.h"

class kSprite : public kMesh2DBase {
private:
	kVec2 _size;

public:
	kSprite(kEngine* engine);
	~kSprite();

	inline void setDiffuse(const kColor& diffuse) {
		for (size_t i = 0; i < 4; i++)
			setColor(i, diffuse);
	}
	inline const kColor& getDiffuse() const {
		return getColor(0);
	}
	inline void setSize(const kVec2& size) {
		_size = size;

		setVertex(0, _size*kVec2(-0.5f, -0.5f));
		setVertex(1, _size*kVec2(0.5f, -0.5f));
		setVertex(2, _size*kVec2(0.5f, 0.5f));
		setVertex(3, _size*kVec2(-0.5f, 0.5f));
	}
	inline void setSize(float width, float height) {
		setSize(kVec2(width, height));
	}
	void setSizeFromMaterial(const kVec2i& frames);
	inline void setSizeFromMaterial() {
		setSizeFromMaterial(kVec2i(1, 1));
	}
	inline const kVec2& getSize() const {
		return _size;
	}
	inline float getWidth() const {
		return _size.x;
	}
	inline float getHeight() const {
		return _size.y;
	}
	inline void setTextureCoord(int vertex, const kVec2& coord) {
		kMesh2DBase::setTextureCoord(vertex, coord);
	}
	void setFrame(int frame);
	void resetTextureCoords();
};
